package com.jd.mysql.mgr.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jd.mysql.mgr.dao.MgrAccountGroupDAO;
import com.jd.mysql.mgr.pojo.MgrAccountGroup;

public class MgrAccountGroupDAOImpl extends HibernateDaoSupport implements MgrAccountGroupDAO {

	public void deleteMgrAccountGroup(MgrAccountGroup mgra) {
		// TODO Auto-generated method stub
		HibernateTemplate temp = this.getHibernateTemplate();
		temp.setFlushMode(HibernateTemplate.FLUSH_EAGER);
		temp.delete(mgra);
	}

	public MgrAccountGroup findMgrAccountGroupByGroupName(String groupName) {
		// TODO Auto-generated method stub
		String hql = "from MgrAccountGroup where mgrGroupName=:mgrGroupName";
		Session session = this.getSession();
		Query query  = session.createQuery(hql);
		query.setString("mgrGroupName", groupName);
		List<MgrAccountGroup> list = new ArrayList<MgrAccountGroup>();
		if(list!=null && list.size()==1){
			return list.get(0);
		}
		return null;
	}

	public MgrAccountGroup findMgrAccountGroupById(Integer id) {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().get(MgrAccountGroup.class, id);
	}

	public List<MgrAccountGroup> getMgrAccountGroupList() {
		// TODO Auto-generated method stub
		String hql = "from MgrAccountGroup";
		Session session = this.getSession();
		Query query  = session.createQuery(hql);
		List<MgrAccountGroup> list = query.list();
		return list;
	}

	public void saveMgrAccountGroup(MgrAccountGroup mgra) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().save(mgra);
	}

	public void updateMgrAccountGroup(MgrAccountGroup mgra) {
		// TODO Auto-generated method stub
		HibernateTemplate temp = this.getHibernateTemplate();
		temp.setFlushMode(HibernateTemplate.FLUSH_EAGER);
		temp.update(mgra);
	}

	
}
